﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq.Mapping;
using System.Data.Linq;

namespace HomeDMSObjectModel
{
    [Table(Name="Document_Tag")]
    public class DocumentTagAssociation
    {
        [Column(Name="document_id",IsPrimaryKey=true)]
        internal int DocumentId { get; set; }


        private EntityRef<Document> _document;

        [Association(Name="FK_DocumentTagAssocciation",Storage="_document",ThisKey="DocumentId",IsForeignKey=true)]
        public Document Document
        {
            get { return _document.Entity; }
            set 
            {
                Document prevValue = _document.Entity;
                if (prevValue != value && _document.HasLoadedOrAssignedValue)
                {
                    if (value != null)
                    {
                        DocumentId = value.DocumentId;
                        _document.Entity = value;
                    }
                }
                else
                {
                    _document.Entity = value;
                }
            }
        }


        [Column(Name="tag_id",IsPrimaryKey=true)]
        internal int TagId { get; set; }

        private EntityRef<Tag> _tag;

        [Association(Name = "FK_TagDocumentAssocciation", Storage = "_tag", ThisKey = "TagId", IsForeignKey = true)]
        public Tag Tag
        {
            get { return _tag.Entity; }
            set {
                Tag prevValue = _tag.Entity;
                if (prevValue != value && _tag.HasLoadedOrAssignedValue)
                {
                    if (value != null)
                    {
                        TagId = value.TagId;
                        _tag.Entity = value;
                    }
                }
                else
                {
                    _tag.Entity = value;
                }
            }
        }
	
    }
}
